import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { isPhone } from "@pureadmin/utils";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  name: [{ required: true, message: "企业名称为必填项", trigger: "blur" }],
  socialCode: [
    {
      required: true,
      message: "企业代码(企业统一社会信用代码)必填项",
      trigger: "blur"
    }
  ],
  shortName: [{ required: true, message: "企业简称为必填项", trigger: "blur" }],
  organizationCode: [
    { required: true, message: "组织机构代码为必填项", trigger: "blur" }
  ],
  businessType: [
    { required: true, message: "企业主要类型为必填项", trigger: "blur" }
  ],
  taxIdentifyNumber: [
    { required: true, message: "纳税人标识为必填项", trigger: "blur" }
  ],
  registerPlace: [
    { required: true, message: "企业注册地为必填项", trigger: "blur" }
  ],
  registerAddress: [
    { required: true, message: "企业注册详细地址为必填项", trigger: "blur" }
  ],
  legalPerson: [
    { required: true, message: "法定代表人为必填项", trigger: "blur" }
  ],
  principal: [
    { required: true, message: "企业负责人为必填项", trigger: "blur" }
  ],
  phone: [
    { required: true, message: "企业联系电话为必填项", trigger: "blur" },
    {
      validator: (rule, value, callback) => {
        if (value === "") {
          callback();
        } else if (!isPhone(value)) {
          callback(new Error("请输入正确的手机号码格式"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ],
  registeredCapital: [
    { required: true, message: "注册资本为必填项", trigger: "blur" }
  ],
  foundDate: [{ required: true, message: "成立时间为必填项", trigger: "blur" }],
  businessTerm: [
    { required: true, message: "营业期限为必填项", trigger: "blur" }
  ],
  businessLongTerm: [
    { required: true, message: "营业期限-长期为必填项", trigger: "blur" }
  ],
  businessScope: [
    { required: true, message: "经营范围为必填项", trigger: "blur" }
  ],
  businessLicense: [
    { required: true, message: "营业执照为必填项", trigger: "blur" }
  ]
});
